package com.bwie.test.consumer;

import com.bwie.common.domain.Data2;
import com.bwie.test.mapper.TestMapper;
import com.bwie.test.service.TestService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * @Author：Mrzou
 * @Package：com.bwie.test.consumer
 * @Project：bwie-zg6test01
 * @name：ConsumerData2
 * @Date：2024/7/7 10:48
 */
@Component
public class ConsumerData2 {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private TestService service;

    @KafkaListener(topics = "topic-two",containerFactory = "kafkaListenerContainerFactory",errorHandler = "myKafkaListenerErrorHandler")
    public void consumerData2(ConsumerRecord<Object,Object> consumerRecord, Acknowledgment acknowledgment){
        String key = (String) consumerRecord.key();
            Data2 data2 = (Data2) consumerRecord.value();
            service.addData2(data2);
            acknowledgment.acknowledge();

    }

}
